#include <iostream>

using namespace std;

const int N = 1e6 + 10;

int q[N], s[N];
int n;
int res;

int main(void)
{
    cin >> n;
    for (int i = 0; i < n; i++)
        scanf("%d", &q[i]);

    int i = 0, j = 0;
    while (j < n)
    {
        s[q[j]]++;
        while (s[q[j]] > 1)
        { // 只有i到达第一个q[j]的右边元素才结束
            s[q[i]]--;
            i++;
        }
        res = max(res, j - i + 1);
        j++;
    }

    cout << res << endl;
}